home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C21 / MemFun3.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  871 b   |  33 lines

  1. //: C21:MemFun3.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Using mem_fun()
  7. #include "NumStringGen.h"
  8. #include <algorithm>
  9. #include <vector>
  10. #include <string>
  11. #include <iostream>
  12. #include <functional>
  13. using namespace std;
  14.  
  15. int main() {
  16.   const int sz = 9;
  17.   vector<string> vs(sz);
  18.   // Fill it with random number strings:
  19.   generate(vs.begin(), vs.end(), NumStringGen());
  20.   copy(vs.begin(), vs.end(), 
  21.     ostream_iterator<string>(cout, "\t"));
  22.   cout << endl;
  23.   const char* vcp[sz];
  24.   transform(vs.begin(), vs.end(), vcp, 
  25.     mem_fun_ref(&string::c_str));
  26.   vector<double> vd;
  27.   transform(vcp,vcp + sz,back_inserter(vd),
  28.     std::atof);
  29.   copy(vd.begin(), vd.end(), 
  30.     ostream_iterator<double>(cout, "\t"));
  31.   cout << endl;
  32. } ///:~
  33.